package com.heima.leetcode.datastructure.hashtable;

/**
 * <strong>查找第一个不重复的字符 387</strong>
 * <p>字符串只包含小写字母</p>
 * @author 勾新杰
 * @version 1.0
 * @date 2024/9/26 21:44
 */
public class FirstUniqueChar {
    public static int firstUniqChar(String s) {
        int[] array = new int[26];
        char[] charArray = s.toCharArray();
        for (char c : charArray) {
            array[c - 'a']++;
        }
        for (int i = 0; i < charArray.length; i++) {
            if (array[charArray[i] - 'a'] == 1){
                return i;
            }
        }
        return -1;
    }
}
